﻿# 初始化环境和智能体
from Game.G3Maze.agent import QLearningAgent
from Game.G3Maze.env import MazeEnv

# 超参数配置
ALPHA = 0.1  # 学习率
GAMMA = 0.99  # 未来奖励折扣
EPSILON_START = 1.0  # 初始探索率
EPSILON_MIN = 0.01  # 最小探索率
DECAY_RATE = 0.995  # 探索率衰减系数


def train_agent(env: MazeEnv, agent: QLearningAgent, steps=1000):
    epsilon = EPSILON_START
    total_rewards = []

    for episode in range(steps):
        obs, score = env.reset()
        action = agent.choose_action()
        reward = env.step(action)
        agent.update(action, reward)

    return total_rewards


env = MazeEnv(render_mode=None)  # 训练时不渲染
agent = QLearningAgent(env)
train_agent(env, agent, steps=2000)
